using IM.Easy.Infrastructure.Query;
using Microsoft.AspNetCore.Mvc;
using IM.Easy.SystemServices.IServices;
using IM.Easy.Entity.System;
using IM.Easy.SystemServices.Dtos;
using IM.Easy.Core.Attributes;

namespace IM.Easy.Api.Controllers.system
{
    /// <summary>
    /// SysRoleMenuController 控制器
    /// </summary>
    [Route("system/permission/menu")]
    public class RoleMenuController : ControllerBase
    {
        private readonly IRoleMenuService _service;

        /// <summary>
        /// 构造函数，注入服务
        /// </summary>
        /// <param name="service">服务接口</param>
        public RoleMenuController(IRoleMenuService service)
        {
            _service = service;
        }

        /// <summary>
        /// 保存
        /// </summary>
        [HttpPost("save/{roleId}")]
        [Api(Name = "保存角色菜单", Perm = "role:menu:save")]
        public void Save([FromRoute] long roleId, [FromBody] params long[] menuIds)
        {
            _service.Save(roleId, menuIds);
        }

        /// <summary>
        /// 获取角色已分配菜单
        /// </summary>
        /// <param name="roleId"></param>
        [HttpGet("assigned/{roleId}")]
        [Api(Name = "获取角色已分配菜单", Perm = "role:menu:assigned")]
        public List<SysMenu> GetAssignedMenus([FromRoute] long roleId)
        {
            return _service.GetMenus(roleId);
        }
    }
}
